<template>
  <div class="page">
    <el-card>
      <h3 class="card_title">已挂载的文件系统</h3>
      <el-table :data="alreadyFileData" border stripe style="width: 100%">
        <el-table-column prop="value1" label="文件系统" min-width="150">
        </el-table-column>
        <el-table-column prop="value2" label="挂载点" min-width="150">
        </el-table-column>
        <el-table-column prop="value3" label="可用" min-width="120">
        </el-table-column>
        <el-table-column prop="value4" label="已用" min-width="120">
        </el-table-column>
      </el-table>
    </el-card>
    <el-card class="l-mg-top20">
      <div class="l-f l-row-sb">
        <div class="l-f">
          <h3 class="card_title">挂载点</h3>
          <el-tooltip class="item" effect="dark" content="配置存储设备挂载到文件系统中的位置和参数。" placement="right">
            <i class="el-icon-warning"></i>
          </el-tooltip>
        </div>
        <el-button type="primary" icon="el-icon-plus" size="small" @click="onAddMount">添加</el-button>
      </div>
      <el-table :data="mountData" border stripe style="width: 100%">
        <el-table-column label="是否启用" width="120" align="center">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.value1"></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="value2" label="设备" min-width="150">
        </el-table-column>
        <el-table-column prop="value2" label="挂载点" min-width="150">
        </el-table-column>
        <el-table-column prop="value3" label="文件系统" min-width="120">
        </el-table-column>
        <el-table-column prop="value4" label="选项" min-width="80">
        </el-table-column>
        <el-table-column prop="value4" label="根文件" min-width="80">
        </el-table-column>
        <el-table-column prop="value4" label="检查" min-width="80">
        </el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template slot-scope="scope">
            <el-button @click="onEdit(scope.row)" type="primary" size="mini">修改</el-button>
            <el-button type="danger" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card class="l-mg-top20">
      <div class="l-f l-row-sb">
        <div class="l-f">
          <h3 class="card_title">SWAP</h3>
          <el-tooltip class="item" effect="dark" content="如果物理内存不足，闲置数据可自动移到交换区暂存，以提高可用内存。" placement="right">
            <i class="el-icon-warning"></i>
          </el-tooltip>
        </div>
        <el-button type="primary" icon="el-icon-plus" size="small" @click="onAddExchange">添加</el-button>
      </div>
      <el-table :data="mountData" border stripe style="width: 100%">
        <el-table-column label="是否启用" width="120" align="center">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.value1"></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="value2" label="设备" min-width="300">
        </el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template slot-scope="scope">
            <el-button @click="onEdit(scope.row)" type="primary" size="mini">修改</el-button>
            <el-button type="danger" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <div class="l-f l-row-c l-mg-top30">
      <el-button type="primary" @click="submitForm('ruleForm')">保存&应用</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')">保 存</el-button>
      <el-button type="primary">复 位</el-button>
    </div>
    <el-dialog title="新增/编辑挂载点" :visible.sync="mountDialogVisible" width="800px">
      <el-form :model="mountForm" ref="mountForm" label-width="100px">
        <el-tabs type="border-card">
          <el-tab-pane label="基本设置">
            <el-form-item label="启用挂载点" prop="name">
              <el-switch
              v-model="mountForm.switch">
            </el-switch>
            </el-form-item>
            <el-form-item label="设备" prop="name">
              <el-input v-model="mountForm.value1" placeholder="请输入设备" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="存储器或分区的设备节点，(例如 /dev/sda1)" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="挂载点" prop="name">
              <el-input v-model="mountForm.value1" placeholder="请输入挂载点" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="指定设备的挂载目录" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="文件系统" prop="name">
              <el-input v-model="mountForm.value1" placeholder="请输入文件系统" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="用于格式化存储器的文件系统，(例如 ext4)" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="文件系统检查" prop="name">
              <el-switch
              v-model="mountForm.value2">
            </el-switch>
            <el-tooltip class="item" effect="dark" content="挂载设备前运行文件系统检查" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane label="高级设置">
            <el-form-item label="UUID" prop="name">
              <el-input v-model="mountForm.value1" placeholder="请输入UUID" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="用UUID来挂载设备" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="卷标" prop="name">
              <el-input v-model="mountForm.value1" placeholder="卷标" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="用卷标来挂载设备" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="设备" prop="name">
              <el-input v-model="mountForm.value1" placeholder="挂载选项" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="详参“mount”联机帮助" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="mountDialogVisible = false">确 定</el-button>
        <el-button type="primary" @click="resetForm('mountForm')">重置</el-button>
        <el-button @click="mountDialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog title="新增/编辑交换项目" :visible.sync="exchangeDialogVisible" width="800px">
      <el-form :model="exchangeForm" ref="exchangeForm" label-width="100px">
        <el-tabs type="border-card">
          <el-tab-pane label="基本设置">
            <el-form-item label="启用交换区" prop="name">
              <el-switch
              v-model="exchangeForm.value1">
            </el-switch>
            </el-form-item>
            <el-form-item label="设备" prop="name">
              <el-input v-model="exchangeForm.value2" placeholder="请输入设备" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="存储器或分区的设备节点，(例如 /dev/sda1)" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane label="高级设置">
            <el-form-item label="UUID" prop="name">
              <el-input v-model="exchangeForm.value2" placeholder="请输入UUID" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="用UUID来挂载设备" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="卷标" prop="name">
              <el-input v-model="exchangeForm.value2" placeholder="卷标" style="width: 60%;"></el-input>
              <el-tooltip class="item" effect="dark" content="用卷标来挂载设备" placement="right">
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </el-form-item>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="exchangeDialogVisible = false">确 定</el-button>
        <el-button type="primary" @click="resetForm('exchangeForm')">重置</el-button>
        <el-button @click="exchangeDialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      alreadyFileData: [
        {
          id: 1,
          value1: 'rootfs',
          value2: '/',
          value3: '1.84 MB / 3.00 MB',
          value4: '39% (1.16 MB)'
        },
        {
          id: 2,
          value1: '/dev/root',
          value2: '/rom',
          value3: '0.00 B / 11.00 MB',
          value4: '100% (11.00 MB)'
        }
      ],
      mountData: [
        {
          id: 1,
          value1: false,
          value2: '/dev/mmcblk0p1',
          value3: '/mnt/sdcard',
          value4: 'vfat',
          value5: 'rw',
          value6: '否',
          value7: '否'
        },
      ],
      swapData: [
        {
          id: 1,
          value1: false,
          value2: '/dev/mmcblk0p1',
        }
      ],
      mountDialogVisible: false,
      mountForm: {
        switch: false,
        name: '',
        value1: '',
        value2: false
      },
      exchangeDialogVisible: false,
      exchangeForm: {
        value1: false,
        value2:  ''
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 新增挂载点
    onAddMount() {
      this.mountDialogVisible = true
    },
    // 新增交换
    onAddExchange() {
      this.exchangeDialogVisible = true
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
}
</script>

<style lang="scss" scoped></style>